<?php
/**
 * 二期上传图片接口
 */
namespace app\index\controller;
use think\Controller;
use think\Request;
use think\Db;
class Upload extends Controller{
	/**
	 * 上传普通图片接口
	 */
	public function upload(){
		header("Access-Control-Allow-Origin: *");
    	header("Access-Control-Allow-Methods: OPTIONS,HEAD,GET,POST,PUT,PATCH,DELETE");
   		header("Access-Control-Allow-Headers:Content-Type,Content-Range,Content-Disposition");
   		set_time_limit(0);
   		$dire = 'images';
   		
   		if(!empty(request()->param('path'))){
   			$dire = request()->param('path');
   		}
   		$path = ROOT_PATH . 'public' . DS .'uploads'.DS.$dire;	//保存的路径
   		makeDir($path);											//确保该目录存在，若不存在，则创建
		$file_name = 'files';
		$files = request()->file($file_name);	//文件对象数组
		if(!$files){
			return rel(-1,'获取文件临时路径失败');
		}else{
			if(is_array($files) || count($files)>1){
				foreach($files as $file){
					$info = $file->move($path);
					if($info){
						$rel.=$dire.DS.$info->getSaveName().',';
					}
				}
				$rel=rtrim($rel,',');	
			}else{
				$info = $files->move($path);
				$rel=$dire.DS.$info->getSaveName();
			}
			return rel(1,'图片上传成功',$rel);
		}
	}
}